/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 17
 * Time: 21:05
 */
//力扣21.合并两个有序链表
class ListNode {
    int val;
    ListNode next;
   ListNode() {}
    ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }
class Solution1 {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode node = new ListNode();
        ListNode t = node;
        ListNode p1 = list1;
        ListNode p2 = list2;
        while(p1 != null && p2 != null) {
            if(p1.val > p2.val) {
                t.next = p2;
                t = t.next;
                p2 = p2.next;
            }else {
                t.next = p1;
                t = t.next;
                p1 = p1.next;
            }
        }
        if(p1 != null) {
            t.next = p1;
        }
        if(p2 != null) {
            t.next = p2;
        }
        return node.next;
    }
}
